﻿using KingRoad.EPM.CompletionMaterialsEntity.Model;
using KingRoad.EPM.Web.Areas.CompletionMaterials.ViewModels;
using KingRoad.EPM.Web.Areas.SafetyConstruction.SafetyConstructionFramework.Common;
using System;
using System.Collections.Generic;
using System.Dynamic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace KingRoad.EPM.Web.Areas.CompletionMaterials.Controllers
{
    public class ArchiveController : BaseController
    {
        /// <summary>
        /// 档案管理-首页
        /// </summary>
        /// <returns></returns>
        public ActionResult Index(string type, string id)
        {
            ArchiveViewModel vm = new ArchiveViewModel();
            ViewBag.Type = type;
            ViewBag.PftId = id;
            //第几页
            ViewBag.pageNum = 1;
            //每页多少条
            ViewBag.numPerPage = 20;
            if (id != null && id != "null" && id != "")
            {
                //案卷表
                string sql = " Pft_ID='" + id + "' ";
                int totalRecord = 0;
                //当前页码
                vm.TheBcdFilelistList = BcdFilelistUIRule.GetEntityListByContionRe(ViewBag.pageNum, ViewBag.numPerPage, "Fl_Numb", out totalRecord, sql, "asc", "View_FileList");
                //总条数
                ViewBag.totalcount = totalRecord;
                //总页数
                ViewBag.pagenumshown = totalRecord % ViewBag.numPerPage == 0 ? totalRecord / ViewBag.numPerPage : totalRecord / ViewBag.numPerPage + 1;
            }
            else
            {
                vm.TheBcdFilelistList = new List<BcdFilelistInfo>();
            }
            return PartialView(vm);
        }
        /// <summary>
        /// 案卷列表分页
        /// </summary>
        /// <returns></returns>
        public ActionResult SplitPage()
        {
            ArchiveViewModel vm = new ArchiveViewModel();
            int totalRecord = 0;
            //当前页码
            ViewBag.pageNum = Convert.ToInt32(Request.Form["pageNum"]);
            //每页多少条
            ViewBag.numPerPage = Convert.ToInt32(Request.Form["numPerPage"]);
            ViewBag.Type = Request.Form["Type"];
            ViewBag.PftId = Request.Form["PftId"];

            if (ViewBag.pageNum == 0 || ViewBag.numPerPage == 0)
                return Index(ViewBag.Type, ViewBag.PftId);
            else
            {
                //工程项目与归档类型与案卷目录对应关系表
                string sql = " Pft_ID='" + ViewBag.PftId + "' ";
                ViewBag.iput_code = Request.Form["iput_code"];
                ViewBag.iput_numb1 = Request.Form["iput_numb1"];
                ViewBag.iput_numb2 = Request.Form["iput_numb2"];
                ViewBag.iput_name = Request.Form["iput_name"];
                if (ViewBag.iput_code != "")
                    sql += " and Fl_Code like '%" + ViewBag.iput_code + "%' ";
                if (ViewBag.iput_numb1 != "")
                {
                    if (IsNumeric(ViewBag.iput_numb1))
                        sql += " and Fl_Numb>=" + ViewBag.iput_numb1;
                }
                if (ViewBag.iput_numb2 != "")
                {
                    if (IsNumeric(ViewBag.iput_numb2))
                        sql += " and Fl_Numb<=" + ViewBag.iput_numb2;
                }
                if (ViewBag.iput_name != "")
                    sql += " and Fl_Item+Fl_FileTitle+Fl_FileName like '%" + ViewBag.iput_name + "%' ";
                //案卷目录表
                vm.TheBcdFilelistList = BcdFilelistUIRule.GetEntityListByContionRe(ViewBag.pageNum, ViewBag.numPerPage, "Fl_Numb", out totalRecord, sql, "asc", "View_FileList");
                //总条数
                ViewBag.totalcount = totalRecord;
                //总页数
                ViewBag.pagenumshown = totalRecord % ViewBag.numPerPage == 0 ? totalRecord / ViewBag.numPerPage : totalRecord / ViewBag.numPerPage + 1;
            }
            return View("Index", vm);
        }

        /// <summary>  
        /// 判断是否是数字  
        /// </summary>  
        /// <param name="str">字符串</param>  
        /// <returns>bool</returns>  
        public bool IsNumeric(string str)
        {
            if (str == null || str.Length == 0)
                return false;
            System.Text.ASCIIEncoding ascii = new System.Text.ASCIIEncoding();
            byte[] bytestr = ascii.GetBytes(str);
            foreach (byte c in bytestr)
            {
                if (c < 48 || c > 57)
                {
                    return false;
                }
            }
            return true;
        }

        #region 案卷增删改查
        /// <summary>
        /// 添加案卷
        /// </summary>
        /// <returns></returns>
        public ActionResult Add(string pftId, bool insert)
        {
            ViewBag.pftId = pftId;
            ViewBag.insert = insert;
            ArchiveViewModel vm = new ArchiveViewModel();
            //案卷目录表
            BcdFilelistInfo info = new BcdFilelistInfo();
            BcdProfiletypeInfo pInfo = BcdProfiletypeUIRule.GetEntityById(new Guid(pftId));
            info.Fl_ID = Guid.NewGuid().ToString().ToUpper();
            info.Pft_ID = pftId;
            info.Fl_FileType = GetFileParTypeName(pInfo.Pft_PIds,pInfo.Fd_Name);
            info.Fl_Code = pInfo.Fd_Code;
            if (!insert)
            {
                //案卷流水号
                string sql = " Fl_Code='" + info.Fl_Code + "' ";
                if (info.Fl_Code.IndexOf(".") >= 0)
                {
                    sql = " Fl_Code like '" + GetFileCode(info.Fl_Code) + "%' ";
                }
                int count = BcdFilelistUIRule.GetNumbBySql(sql);
                if (count == 0)
                {
                    List<BcdFilelistInfo> flList = BcdFilelistUIRule.GetEntityListBySql(sql);
                    count = flList.Count;
                }
                //自增长
                info.Fl_Numb = count + 1;
            }
            info.Fl_Item = pInfo.P_Name;
            info.Fl_Unit = pInfo.Pft_Unit;
            info.Fl_Kept = pInfo.Fd_Kept;
            vm.TheBcdFilelistInfo = info;
            return View(vm);
        }
        /// <summary>
        /// 添加案卷页面提交
        /// </summary>
        /// <param name="vm"></param>
        /// <returns></returns>
        [HttpPost]
        public JsonResult AddPost(ArchiveViewModel vm)
        {
            bool codeState = true;
            var isScuess = TryCatchCommand.TryExec(() =>
            {
                bool insert = Convert.ToBoolean(Request.Form["iput_insert"]);
                if (insert)
                {
                    //如果是插入案卷操作
                    string sql = " Fl_Code='" + vm.TheBcdFilelistInfo.Fl_Code + "' ";
                    if (vm.TheBcdFilelistInfo.Fl_Code.IndexOf(".") >= 0)
                    {
                        sql = " Fl_Code like '" + GetFileCode(vm.TheBcdFilelistInfo.Fl_Code) + "%' ";
                    }
                    int count = BcdFilelistUIRule.GetCountBySql(sql + " and Fl_Numb=" + vm.TheBcdFilelistInfo.Fl_Numb);
                    if (count > 0)
                    {
                        //档案流水号已存在 将此流水号及比它大的流水号+1
                        BcdFilelistUIRule.InsertNumb(sql + " and Fl_Numb>=" + vm.TheBcdFilelistInfo.Fl_Numb);
                    }
                }
                else
                {
                    if (GetFileCodeCount(vm.TheBcdFilelistInfo.Fl_Code, vm.TheBcdFilelistInfo.Fl_Numb) > 0)
                    {
                        //档案号已经存在,禁止添加
                        codeState = false;
                    }
                }
                if (codeState)
                {
                    //添加  案卷信息
                    vm.TheBcdFilelistInfo.Fl_OperateUserID = GetLoginUserId;              //操作人ID及名称 添加权限时赋值
                    vm.TheBcdFilelistInfo.Fl_OperateUserName = GetLoginUserRealName;
                    vm.TheBcdFilelistInfo.Fl_OperateTime = DateTime.Now;
                    BcdFilelistUIRule.InsertEntity(vm.TheBcdFilelistInfo);
                }
            });

            dynamic jsonReturn = new ExpandoObject();

            //保存成功
            if (isScuess)
            {
                if (codeState)
                {
                    jsonReturn = new
                    {
                        statusCode = "200",
                        message = "添加成功",
                        type = "add",
                        navTabId = "",
                        rel = "",
                        callbackType = "",
                        forwardUrl = "",
                        confirmMsg = ""
                    };
                }
                else
                {
                    jsonReturn = new
                    {
                        statusCode = "300",
                        message = "档案号已存在，请更换！",
                    };
                }
            }
            else
            {
                jsonReturn = new
                {
                    statusCode = "300",
                    message = "添加失败",
                };
            }

            return new JsonResult()
            {
                Data = jsonReturn
            };
        }

        /// <summary>
        /// 修改案卷
        /// </summary>
        /// <returns></returns>
        public ActionResult Edit(string id)
        {
            ArchiveViewModel vm = new ArchiveViewModel();
            vm.TheBcdFilelistInfo = BcdFilelistUIRule.GetEntityById(new Guid(id));
            return View(vm);
        }
        /// <summary>
        /// 修改案卷页面提交
        /// </summary>
        /// <param name="vm"></param>
        /// <returns></returns>
        [HttpPost]
        public JsonResult EditPost(ArchiveViewModel vm)
        {
            bool codeState = true;
            var isScuess = TryCatchCommand.TryExec(() =>
            {
                if (GetFileCodeCount(vm.TheBcdFilelistInfo.Fl_Code, vm.TheBcdFilelistInfo.Fl_Numb, vm.TheBcdFilelistInfo.Fl_ID) > 0)
                {
                    //档案号已经存在,禁止修改
                    codeState = false;
                }
                if (codeState)
                {
                    //修改  案卷信息
                    vm.TheBcdFilelistInfo.Fl_OperateUserID = GetLoginUserId;              //操作人ID及名称 添加权限时赋值
                    vm.TheBcdFilelistInfo.Fl_OperateUserName = GetLoginUserRealName;
                    vm.TheBcdFilelistInfo.Fl_OperateTime = DateTime.Now;
                    BcdFilelistUIRule.UpdateEntity(vm.TheBcdFilelistInfo);
                }
            });

            dynamic jsonReturn = new ExpandoObject();

            //保存成功
            if (isScuess)
            {
                if (codeState)
                {
                    jsonReturn = new
                    {
                        statusCode = "200",
                        message = "修改成功",
                        type = "eidt",
                        navTabId = "",
                        rel = "",
                        callbackType = "",
                        forwardUrl = "",
                        confirmMsg = ""
                    };
                }
                else
                {
                    jsonReturn = new
                    {
                        statusCode = "300",
                        message = "档案号已存在，请更换！",
                    };
                }
            }
            else
            {
                jsonReturn = new
                {
                    statusCode = "300",
                    message = "修改失败",
                };
            }

            return new JsonResult()
            {
                Data = jsonReturn
            };
        }

        /// <summary>
        /// 删除案卷
        /// </summary>
        /// <param name="vm"></param>
        /// <returns></returns>
        [HttpPost]
        public JsonResult Del(string pftId, string id)
        {
            var isScuess = TryCatchCommand.TryExec(() =>
            {
                BcdFilelistUIRule.DeleteEntity(id);
            });

            dynamic jsonReturn = new ExpandoObject();

            //保存成功
            if (isScuess)
            {
                jsonReturn = new
                {
                    statusCode = "200",
                    message = "删除成功",
                    type = "check",
                    navTabId = "",
                    id = pftId,
                    name = GetNodeName(pftId),
                    rel = "",
                    callbackType = "",
                    forwardUrl = "",
                    confirmMsg = ""
                };
            }
            else
            {
                jsonReturn = new
                {
                    statusCode = "300",
                    message = "删除失败",
                };
            }

            return new JsonResult()
            {
                Data = jsonReturn
            };
        }

        /// <summary>
        /// 查看案卷信息
        /// </summary>
        /// <returns></returns>
        public ActionResult Detail(string id)
        {
            ArchiveViewModel vm = new ArchiveViewModel();
            vm.TheBcdFilelistInfo = BcdFilelistUIRule.GetEntityById(new Guid(id));
            vm.TheBcdVolumedirectoryList = BcdVolumedirectoryUIRule.GetEntityListBySql(" Fl_ID='" + id + "' ");
            vm.TheBcdVolumedirectoryList.ForEach(t =>
            {
                t.FilePath = FilePath(t.Vd_ID, t.Pft_ID);
                t.FileCount = GetFilesCount(Server.MapPath(String.Format("~/Files/{0}", t.FilePath)), 0);
            });
            return View(vm);
        }
        #endregion

        #region 卷内目录管理
        /// <summary>
        /// 卷内目录首页
        /// </summary>
        /// <returns></returns>
        public ActionResult Volume(string type, string pftId, string id)
        {
            ViewBag.Type = type;
            ViewBag.PftId = pftId;
            ArchiveViewModel vm = new ArchiveViewModel();
            vm.TheBcdFilelistInfo = BcdFilelistUIRule.GetEntityById(new Guid(id));
            return View(vm);
        }
        /// <summary>
        /// 卷内目录列表
        /// </summary>
        /// <returns></returns>
        public ActionResult VolumedirectoryList(string id)
        {
            ArchiveViewModel vm = new ArchiveViewModel();
            vm.TheBcdFilelistInfo = BcdFilelistUIRule.GetEntityById(new Guid(id));
            vm.TheBcdVolumedirectoryList = BcdVolumedirectoryUIRule.GetEntityListBySql(" Fl_ID='" + id + "' ");
            return PartialView(vm);
        }
        /// <summary>
        /// 归档材料列表
        /// </summary>
        /// <param name="proId"></param>
        /// <param name="fId"></param>
        /// <returns></returns>
        public ActionResult VolumeList(string flId, string pftId)
        {
            ViewBag.FlId = flId;
            ArchiveViewModel vm = new ArchiveViewModel();
            string sql = " Fl_ID is null and Vd_State=1 and Pft_ID='" + pftId + "' ";
            vm.TheBcdVolumedirectoryList = BcdVolumedirectoryUIRule.GetEntityListBySql(sql);
            return View(vm);
        }
        /// <summary>
        /// 添加未归档文件提交
        /// </summary>
        /// <param name="vm"></param>
        /// <returns></returns>
        [HttpPost]
        public JsonResult FileVolumeAdd()
        {
            string flid = Request.Form["input_flid"];
            BcdFilelistInfo info = BcdFilelistUIRule.GetEntityById(new Guid(flid));
            var isScuess = TryCatchCommand.TryExec(() =>
            {
                string ids = Request.Form["ids"];
                foreach (string id in ids.Split(','))
                {
                    BcdVolumedirectoryInfo vInfo = BcdVolumedirectoryUIRule.GetEntityById(new Guid(id));
                    vInfo.Vd_State = 2;
                    vInfo.Fl_ID = flid;
                    vInfo.Vd_OperateTime = DateTime.Now;
                    vInfo.Vd_OperateUserID = GetLoginUserId;
                    vInfo.Vd_OperateUserName = GetLoginUserName;
                    BcdVolumedirectoryUIRule.UpdateEntity(vInfo);
                }
                //修改  案卷操作人信息
                info.Fl_OperateUserID = GetLoginUserId;              //操作人ID及名称
                info.Fl_OperateUserName = GetLoginUserRealName;
                info.Fl_OperateTime = DateTime.Now;
                BcdFilelistUIRule.UpdateEntity(info);
            });
            dynamic jsonReturn = new ExpandoObject();

            //保存成功
            if (isScuess)
            {
                jsonReturn = new
                {
                    statusCode = "200",
                    message = "添加成功",
                    type = "check",
                    id = info.Pft_ID,
                    name = GetNodeName(info.Pft_ID),
                    navTabId = "CompletionMaterials.FileData.Index",
                    rel = "",
                    callbackType = "",
                    forwardUrl = "",
                    confirmMsg = ""
                };
            }
            else
            {
                jsonReturn = new
                {
                    statusCode = "300",
                    message = "添加失败",
                };
            }

            return new JsonResult()
            {
                Data = jsonReturn
            };
        }
        /// <summary>
        /// 拆出文件
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpPost]
        public JsonResult VolumeSplit(string id)
        {
            BcdVolumedirectoryInfo info = BcdVolumedirectoryUIRule.GetEntityById(new Guid(id));
            var isScuess = TryCatchCommand.TryExec(() =>
            {
                BcdVolumedirectoryUIRule.SplitVolume(id);

                BcdFilelistInfo finfo = BcdFilelistUIRule.GetEntityById(new Guid(info.Fl_ID));
                //修改  案卷操作人信息
                finfo.Fl_OperateUserID = GetLoginUserId;              //操作人ID及名称
                finfo.Fl_OperateUserName = GetLoginUserRealName;
                finfo.Fl_OperateTime = DateTime.Now;
                BcdFilelistUIRule.UpdateEntity(finfo);
            });

            dynamic jsonReturn = new ExpandoObject();
            //保存成功
            if (isScuess)
            {
                jsonReturn = new
                {
                    statusCode = "200",
                    message = "拆出成功",
                    type = "check",
                    id = info.Pft_ID,
                    name = GetNodeName(info.Pft_ID),
                    navTabId = "CompletionMaterials.FileData.Index",
                    rel = "",
                    callbackType = "",
                    forwardUrl = "",
                    confirmMsg = ""
                };
            }
            else
            {
                jsonReturn = new
                {
                    statusCode = "300",
                    message = "拆出失败",
                };
            }

            return new JsonResult()
            {
                Data = jsonReturn
            };
        }
        /// <summary>
        /// 卷内目录序号、页数更新
        /// </summary>
        /// <param name="vm"></param>
        /// <returns></returns>
        [HttpPost]
        public JsonResult VolumeListUpdate(ArchiveViewModel vm)
        {
            var isScuess = TryCatchCommand.TryExec(() =>
            {
                if (vm.TheBcdVolumedirectoryList != null)
                {
                    string flId = "";
                    foreach (BcdVolumedirectoryInfo info in vm.TheBcdVolumedirectoryList)
                    {
                        BcdVolumedirectoryInfo vInfo = BcdVolumedirectoryUIRule.GetEntityById(new Guid(info.Vd_ID));
                        vInfo.Vd_Order = info.Vd_Order;
                        vInfo.Vd_Page = info.Vd_Page;
                        vInfo.Vd_OperateTime = DateTime.Now;
                        vInfo.Vd_OperateUserID = GetLoginUserId;
                        vInfo.Vd_OperateUserName = GetLoginUserName;
                        BcdVolumedirectoryUIRule.UpdateEntity(vInfo);

                        flId = vInfo.Fl_ID;
                    }

                    BcdFilelistInfo finfo = BcdFilelistUIRule.GetEntityById(new Guid(flId));
                    //修改  案卷操作人信息
                    finfo.Fl_OperateUserID = GetLoginUserId;              //操作人ID及名称
                    finfo.Fl_OperateUserName = GetLoginUserRealName;
                    finfo.Fl_OperateTime = DateTime.Now;
                    BcdFilelistUIRule.UpdateEntity(finfo);
                }
            });
            dynamic jsonReturn = new ExpandoObject();

            //保存成功
            if (isScuess)
            {
                jsonReturn = new
                {
                    statusCode = "200",
                    message = "保存成功",
                    type = "add",
                    navTabId = "",
                    rel = "",
                    callbackType = "",
                    forwardUrl = "",
                    confirmMsg = ""
                };
            }
            else
            {
                jsonReturn = new
                {
                    statusCode = "300",
                    message = "保存失败",
                };
            }

            return new JsonResult()
            {
                Data = jsonReturn
            };
        }
        #endregion

        #region 拆卷
        /// <summary>
        /// 拆卷弹出框
        /// </summary>
        /// <param name="type"></param>
        /// <param name="pftId"></param>
        /// <param name="id"></param>
        /// <returns></returns>
        public ActionResult Split(string type, string pftId, string id)
        {
            ViewBag.Type = type;
            ViewBag.PftId = pftId;
            ViewBag.FlId = id;
            ArchiveViewModel vm = new ArchiveViewModel();
            //卷内目录列表
            vm.TheBcdVolumedirectoryList = BcdVolumedirectoryUIRule.GetEntityListBySql(" Fl_ID='" + id + "' ");
            //旧案卷信息
            BcdFilelistInfo info = BcdFilelistUIRule.GetEntityById(new Guid(id));
            //新案卷信息
            vm.TheBcdFilelistInfo = new BcdFilelistInfo();
            vm.TheBcdFilelistInfo.Fl_ID = Guid.NewGuid().ToString().ToUpper();
            vm.TheBcdFilelistInfo.Pft_ID = pftId;
            vm.TheBcdFilelistInfo.Fl_FileType = info.Fl_FileType;
            vm.TheBcdFilelistInfo.Fl_Code = info.Fl_Code;
            string sql = " Fl_Code='" + info.Fl_Code + "' ";
            if (info.Fl_Code.IndexOf(".") >= 0)
            {
                sql = " Fl_Code like '" + GetFileCode(info.Fl_Code) + "%' ";
            }
            int count = BcdFilelistUIRule.GetNumbBySql(sql);
            if (count == 0)
            {
                List<BcdFilelistInfo> flList = BcdFilelistUIRule.GetEntityListBySql(sql);
                count = flList.Count;
            }
            //自增长
            vm.TheBcdFilelistInfo.Fl_Numb = count + 1;
            vm.TheBcdFilelistInfo.Fl_Item = info.Fl_Item;
            vm.TheBcdFilelistInfo.Fl_Unit = info.Fl_Unit;
            vm.TheBcdFilelistInfo.Fl_Kept = info.Fl_Kept;
            return View(vm);
        }
        /// <summary>
        /// 判断档案号是否已存在
        /// </summary>
        /// <param name="code">档案号</param>
        /// <param name="numb">流水号</param>
        /// <returns></returns>
        public int IsCodeExist(string code, int numb)
        {
            return GetFileCodeCount(code, numb);
        }
        /// <summary>
        /// 拆卷提交
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public JsonResult SplitPost(ArchiveViewModel vm)
        {
            string pftId = Request.Form["input_pftId"];
            string flId = Request.Form["input_flId"];
            var isScuess = TryCatchCommand.TryExec(() =>
            {
                if (vm.TheBcdFilelistInfo != null)
                {
                    //拆出新卷
                    //添加  新案卷信息
                    vm.TheBcdFilelistInfo.Fl_OperateUserID = GetLoginUserId;              //操作人ID及名称 添加权限时赋值
                    vm.TheBcdFilelistInfo.Fl_OperateUserName = GetLoginUserRealName;
                    vm.TheBcdFilelistInfo.Fl_OperateTime = DateTime.Now;
                    BcdFilelistUIRule.InsertEntity(vm.TheBcdFilelistInfo);
                    //修改 卷内目录
                    string ids = Request.Form["ids"];
                    foreach (string id in ids.Split(','))
                    {
                        BcdVolumedirectoryInfo vInfo = BcdVolumedirectoryUIRule.GetEntityById(new Guid(id));
                        vInfo.Fl_ID = vm.TheBcdFilelistInfo.Fl_ID;
                        vInfo.Vd_OperateTime = DateTime.Now;
                        vInfo.Vd_OperateUserID = GetLoginUserId;
                        vInfo.Vd_OperateUserName = GetLoginUserName;
                        BcdVolumedirectoryUIRule.UpdateEntity(vInfo);
                    }
                }
                else
                {
                    //直接拆卷
                    string ids = Request.Form["ids"];
                    foreach (string id in ids.Split(','))
                    {
                        BcdVolumedirectoryUIRule.SplitVolume(id);
                    }
                }

                BcdFilelistInfo finfo = BcdFilelistUIRule.GetEntityById(new Guid(flId));
                //修改  案卷操作人信息
                finfo.Fl_OperateUserID = GetLoginUserId;              //操作人ID及名称
                finfo.Fl_OperateUserName = GetLoginUserRealName;
                finfo.Fl_OperateTime = DateTime.Now;
                BcdFilelistUIRule.UpdateEntity(finfo);
            });
            dynamic jsonReturn = new ExpandoObject();

            //保存成功
            if (isScuess)
            {
                jsonReturn = new
                {
                    statusCode = "200",
                    message = "拆卷成功",
                    type = "check",
                    id = pftId,
                    name = GetNodeName(pftId),
                    navTabId = "",
                    rel = "",
                    callbackType = "",
                    forwardUrl = "",
                    confirmMsg = ""
                };
            }
            else
            {
                jsonReturn = new
                {
                    statusCode = "300",
                    message = "拆卷失败",
                };
            }

            return new JsonResult()
            {
                Data = jsonReturn
            };
        }
        #endregion

        #region 导出
        /// <summary>
        /// 导出案卷
        /// </summary>
        /// <returns></returns>
        public void ExportFile(string id)
        {
            BcdFilelistInfo info = BcdFilelistUIRule.GetEntityById(new Guid(id));
            info.Fl_Name = info.Fl_Item + info.Fl_FileTitle + info.Fl_FileName;
            List<BcdVolumedirectoryInfo> list = BcdVolumedirectoryUIRule.GetEntityListBySql(" Fl_ID='" + id + "' ");
            base.ExportFileToWord(info, list);
        }

        /// <summary>
        /// 导出案卷目录
        /// </summary>
        /// <returns></returns>
        public void ExportList(string pftId, string code, string numb1, string numb2, string name)
        {
            //工程项目与归档类型与案卷目录对应关系表
            string sql = " Pft_ID='" + pftId + "' ";
            if (code != "")
                sql += " and Fl_Code like '%" + code + "%' ";
            if (numb1 != "")
            {
                if (IsNumeric(numb1))
                    sql += " and Fl_Numb>=" + numb1;
            }
            if (numb2 != "")
            {
                if (IsNumeric(numb2))
                    sql += " and Fl_Numb<=" + numb2;
            }
            if (name != "")
                sql += " and Fl_Item+Fl_FileTitle+Fl_FileName like '%" + name + "%' ";
            List<BcdFilelistInfo> list = BcdFilelistUIRule.GetEntityListBySql(sql);
            string fileName = "案卷目录.docx";
            int i = 0;
            foreach (BcdFilelistInfo info in list)
            {
                i++;
                info.index = i.ToString();
                info.Fl_Code = info.Fl_Code + info.Fl_Numb.ToString("D3");
                info.Fl_FileName = info.Fl_Item + info.Fl_FileTitle + info.Fl_FileName;
            }
            ExportToWord(fileName, list);
        }
        #endregion
    }
}
